#
#	genx_helpers.py
#
#	David Janes
#	2008.08.16
#
#	GenX - search, create and insert structured data
#

import sys
import types
import re
import os
import os.path
import pprint

#
#	Every template has "capabilities": this latter will be usable to do filtering
#
CAP_GENCARD = "gencard"

CAP_HTML = "html"
CAP_XHTML = "xhtml"
CAP_XML = "xml"
CAP_N3 = "n3"

CAP_MICROFORMATS = "microformats"
CAP_HITEM = "hitem"
CAP_HATOM = "hatom"
CAP_HCARD = "hcard"
CAP_HCALENDAR = "hcalendar"
CAP_HAUDIO = "haudio"

CAP_RDFA = "rdfa"

KEY_IID = "_iid"				## unique IID for this item
KEY_INDEX = "_index"			## index in result set
KEY_TITLE_SHORT = "_short"		## the text that will be substituted back in
KEY_TITLE_FULL = "_full"		## the proper title, especially for GenCard
KEY_TITLE_LIST = "_list"		## used for listing results
KEY_IMAGE_URI = "image_uri"		## the photo, often used in GenCard

metaweb_re = '[$]([0-9A-F]{4,4})'
metaweb_rex = re.compile(metaweb_re, re.I)

def metaweb_decode(s):
	"""Freebase data result decodedr"""
	return	metaweb_rex.sub(lambda m: unichr(int(m.group(0)[1:], 16)), s)

def add_module(name):
	"""Add a module to sys.path; we can make this more sophisticated"""

	if name not in sys.path:
		sys.path.append(name)
